<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>checked属性</title>
</head>
<body>
    <label>
        <input type="checkbox" class="checkbox">寻
    </label>
    <div style="margin-top: 20px">
        <button class="toggle">切换</button>
    </div>
    <script>
        let checkbox = document.querySelector('.checkbox');
        let toggleBtn = document.querySelector('.toggle');

        toggleBtn.onclick = function () {
            let checked = checkbox.getAttribute('checked');
            if (checked){
                checkbox.removeAttribute('checked');

            }else {
                checkbox.setAttribute('checked','checked');
            }
        }
    </script>
</body>
</html>